//
//  RecommendCell.m
//  Four_Fit_New
//
//  Created by lanou on 16/7/14.
//  Copyright © 2016年 xmaz. All rights reserved.
//

#import "RecommendCell.h"
#import "RecTableModel.h"
@interface RecommendCell()

@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UIImageView *photo;


@end

@implementation RecommendCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setCellWithModel:(RecTableModel *)model{
    
    self.title.text = model.title;
    
    NSString *photoUrl = [model.photo substringFromIndex:8];
    
    [self.photo sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://ft-info.fit-time.cn/%@",photoUrl]]];
    
}

- (void)cellOnTableView:(UITableView *)tableView didScrollOnView:(UIView *)view
{
    [self layoutIfNeeded];
    self.photo.contentMode = UIViewContentModeScaleAspectFill;
    
    CGRect rectInSuperview = [tableView convertRect:self.frame toView:view];
    
    float distanceFromCenter = CGRectGetHeight(view.frame)/2 - CGRectGetMinY(rectInSuperview);
     float difference = CGRectGetHeight(self.photo.frame) - CGRectGetHeight(self.frame);
    float move = (distanceFromCenter / CGRectGetHeight(view.frame)) * difference;
    
    CGRect imageRect = self.photo.frame;
    imageRect.origin.y = -(difference/2)+move;
    self.photo.frame = imageRect;
    
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
